﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace ZoeEngine.Services.Content
{
    class ContentProvider : GameComponent, IContentService
    {
        private ContentManager _contentManager = null;

        public ContentProvider(Game game)
            : base(game)
        {
            if (game.Services.GetService(typeof(IContentService)) != null)
            {
                throw new ArgumentException("A content provider already exists.");
            }
            game.Services.AddService(typeof(IContentService), this);
            _contentManager = new ContentManager(game.Services, "Content");
            game.Content = _contentManager;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.Game.Services.GetService(typeof(IContentService)) == this)
                {
                    this.Game.Services.RemoveService(typeof(IContentService));
                }
            }
            base.Dispose(disposing);
        }
        public T Load<T>(string assetName)
        {
            return _contentManager.Load<T>(assetName);
        }
        public void Unload()
        {
            _contentManager.Unload();
        }
    }
}
